package Frame.screen;

import FCRendering.FCRConstants;
import FCRendering.FCRMaster;
import FCRendering.ImageUtil;
import VWorldGameStudio.FCItem;
import VWorldGameStudio.events.ShopEvent;

import java.awt.*;

import static FCRendering.FCRMaster.fcv;
import static FCRendering.FCRMaster.itemLib;

//售卖机界面
public class ShopVedingScreen extends IScreen{
    Font font5;

    @Override
    public void dispatchPaintComponent(Graphics g, FCRMaster fcrMaster) {
        // 渲染售货机打开界面
        if (fcv.isShopVedingOpen()) {
            g.setColor(Color.white);
            g.setFont(font5);
            g.drawImage(ImageUtil.getImage("shopvendingmachine"), (int) (560 * fcv.getProportion()),
                    (int) (240 * fcv.getProportion()), (int) (800 * fcv.getProportion()), (int) (600 * fcv.getProportion()), this);
            ShopEvent shopEvent = (ShopEvent) fcv.getPlayingEvent();
            for (int i = 0; i < shopEvent.getItemid().size(); i++) {
                FCItem item = itemLib.getItemOfID(shopEvent.getItemid().get(i));
                if (i < 3) {
                    g.drawImage(item.getPngPng(),
                            (int) ((244 * i + 604) * fcv.getProportion()), (int) (277 * fcv.getProportion()),
                            (int) (102 * fcv.getProportion()), (int) (102 * fcv.getProportion()), this);
                    g.drawString(item.getChName(),
                            (int) ((244 * i + 710) * fcv.getProportion()), (int) (307 * fcv.getProportion()));
                    g.drawString(item.getBuyInPrice() + "G", (int) ((244 * i + 710) * fcv.getProportion()),
                            (int) (359 * fcv.getProportion()));
                } else {
                    g.drawImage(item.getPngPng(),
                            (int) ((244 * i + 604) * fcv.getProportion()), (int) (401 * fcv.getProportion()),
                            (int) (102 * fcv.getProportion()), (int) (102 * fcv.getProportion()), this);
                    g.drawString(item.getChName(),
                            (int) ((244 * i + 710) * fcv.getProportion()), (int) (431 * fcv.getProportion()));
                    g.drawString(item.getBuyInPrice() + "G", (int) ((244 * i + 710) * fcv.getProportion()),
                            (int) (483 * fcv.getProportion()));
                }
            }
            g.drawString(fcv.getShopVendingTip(), (int) (604 * fcv.getProportion()), (int) (712 * fcv.getProportion()));
            // 选中框
            if (fcv.getShopVendingSelectNum() > 0 && fcv.getShopVendingSelectNum() < 4)
                g.drawRect((int) ((244 * (fcv.getShopVendingSelectNum() - 1) + 604) * fcv.getProportion()),
                        (int) (277 * fcv.getProportion()), (int) (225 * fcv.getProportion()), (int) (102 * fcv.getProportion()));
            if (fcv.getShopVendingSelectNum() > 3)
                g.drawRect((int) ((244 * (fcv.getShopVendingSelectNum() - 4) + 604) * fcv.getProportion()),
                        (int) (401 * fcv.getProportion()), (int) (225 * fcv.getProportion()), (int) (102 * fcv.getProportion()));
            // 灯
//					if(shopvendingselectnum>0)
            if (fcv.getShopLampNum() >= 0)
                if (fcv.getShopLampNum() == 0 || fcv.getShopLampNum() == 8)
                    g.drawImage(ImageUtil.getImage("shoplampredbig"),
                            (int) (fcv.getShopLampCoor()[fcv.getShopLampNum()][0] * fcv.getProportion()),
                            (int) (fcv.getShopLampCoor()[fcv.getShopLampNum()][1] * fcv.getProportion()), (int) (57 * fcv.getProportion()),
                            (int) (63 * fcv.getProportion()), this);
                else
                    g.drawImage(ImageUtil.getImage("shoplampred"),
                            (int) (fcv.getShopLampCoor()[fcv.getShopLampNum()][0] * fcv.getProportion()),
                            (int) (fcv.getShopLampCoor()[fcv.getShopLampNum()][1] * fcv.getProportion()), (int) (25 * fcv.getProportion()),
                            (int) (25 * fcv.getProportion()), this);
            // 进入框
            if (fcv.getShopVendingEnterNum() > 0 && fcv.getShopVendingEnterNum() < 4)
                g.drawRect((int) ((244 * (fcv.getShopVendingEnterNum() - 1) + 604) * fcv.getProportion()),
                        (int) (277 * fcv.getProportion()), (int) (225 * fcv.getProportion()), (int) (102 * fcv.getProportion()));
            if (fcv.getShopVendingEnterNum() > 3)
                g.drawRect((int) ((244 * (fcv.getShopVendingEnterNum() - 4) + 604) * fcv.getProportion()),
                        (int) (401 * fcv.getProportion()), (int) (225 * fcv.getProportion()), (int) (102 * fcv.getProportion()));
        }
    }

    @Override
    protected void setBounds() {
        font5 = new Font(FCRConstants.FONT_BLACK, 0, (int) (30 * fcv.getProportion()));
    }
}
